
<div>
  <h1><%= @promotion.new_record? ? "新建商品活动" : "修改商品活动 ##{params[:id]}" %></h1>
</div>

<div class="form-body">
  <%= form_for @promotion,
    url: (@promotion.new_record? ? admin_promotions_path : admin_promotion_path(@promotion)),
    method: (@promotion.new_record? ? 'post' : 'put'),
    html: { class: 'form-horizontal' } do |f| %>

    <% unless @promotion.errors.blank? %>
      <div class="alert alert-danger">
        <ul class="list-unstyled">
          <% @promotion.errors.messages.values.flatten.each do |error| %>
            <li><i class="fa fa-exclamation-circle"></i> <%= error %></li>
          <% end -%>
        </ul>
      </div>
    <% end -%>

    <div class="form-group">
      <label for="name" class="col-sm-2 control-label">商品活动名*:</label>
      <div class="col-sm-5">
        <%= f.text_field :title, class: "form-control", id: 'title' %>
      </div>
    </div>

    <div class="form-group">
      <label for="name" class="col-sm-2 control-label">商品活动简介*:</label>
      <div class="col-sm-5">
        <%= f.text_field :summary, class: "form-control", id: 'summary' %>
      </div>
    </div>

    <div class="form-group">
      <label for="name" class="col-sm-2 control-label">开始时间*:</label>
      <div class="col-sm-5">
        <calendar value="<%= convert_promotion_date(@promotion.started_at) %>" :name="statedAtName" :disabled-days-of-week="disabled" :format="format" :clear-button="clear" :placeholder="placeholder"></calendar>
      </div>
    </div>

    <div class="form-group">
      <label for="name" class="col-sm-2 control-label">结束时间*:</label>
      <div class="col-sm-5">
        <calendar value="<%= convert_promotion_date(@promotion.ended_at) %>" :name="endedAtName" :disabled-days-of-week="disabled" :format="format" :clear-button="clear" :placeholder="placeholder"></calendar>
      </div>
    </div>

    <div class="form-group">
      <label for="name" class="col-sm-2 control-label">活动描述*:</label>
      <div class="col-sm-5">
        <%= f.text_field :desc, class: "form-control", id: 'desc' %>
      </div>
    </div>

    <div class="form-group">
      <label for="name" class="col-sm-2 control-label">活动折扣*:</label>
      <div class="col-sm-5">
        <%= f.number_field :discount, class: "form-control", id: 'desc', min: 0, max: 1, step: 0.01 %>
      </div>
    </div>

    <div class="form-group">
      <label for="name" class="col-sm-2 control-label">挑选产品*:</label>
      <div class="col-sm-8">
        <product-picker :item-id="<%= @promotion.new_record? ? 0 : @promotion.id %>" :custom-fun="promotionsCallback()"></product-picker>
      </div>
    </div>

    <%= f.hidden_field :product_ids, id: 'hidden_product_ids' %>

    <div class="form-group">
      <div class="col-sm-offset-2 col-sm-8">
        <%= f.submit (@promotion.new_record? ? "新建商品活动" : "编辑商品活动"), class: "btn btn-primary" %>
      </div>
    </div>

  <% end -%>
</div>
